import 'package:flutter/material.dart';

import 'components.dart';
import 'webView.dart';

// class PageIndex extends StatelessWidget {
//   const PageIndex({ Key? key }) : super(key: key);

//   @override
//   Widget build(BuildContext context){
//     return Row(
//       children: [
//         SizedBox(
//           width: 100,
//           child: ListView.builder(
//             itemCount: componentList.length,
//             itemBuilder:(context, index) {
//               return TextButton(
//                 child: Text(componentList[index]["componentName"] ?? ""),
//                 onPressed: () {

//                 },
//               );
//             }
//           ),
//         ),
//         const SizedBox(
//           child: Text("12"),
//         )
//       ],
//     );
//   }
// }

class PageIndex extends StatefulWidget {
  const PageIndex({ Key? key }) : super(key: key);

  @override
  _IndexState createState() => _IndexState();
}

class _IndexState extends State<PageIndex> {

  int activitIndex = 0;

  @override
  Widget build(BuildContext context) {
    // // webView示例
    // return Container(
    //   child: const MyWebView(),
    // );
    // 组件预览
    return Row(
      children: [
        Container(
          decoration: const BoxDecoration(
            border: Border(
              right: BorderSide(
                color: Colors.blue,
                width: 3
              )
            )
          ),
          child: SizedBox(
            width: 120,
            child: ListView.builder(
              itemCount: componentList.length,
              itemBuilder:(context, index) {
                return TextButton(
                  child: Text(componentList[index]["componentName"] as String? ?? ""),
                  onPressed: () {
                    setState(() {
                      activitIndex = index;
                    });
                  },
                );
              }
            ),
          ),
        ),
        SizedBox(
          width: 400,
          child: Padding(
            padding: const EdgeInsets.only(top: 20, bottom: 20),
            child: componentList[activitIndex]["component"]! as Widget,
          ),
        )
      ],
    );
  }
}